#include <bits/stdc++.h>
#include "../../tools/tools.h"
using namespace std;

constexpr int INF = 0x7fffffff; // 无穷大
typedef long long ll;

class Solution {
public:
    int maximumLength(vector<int>& nums) {
        const int n = nums.size();
        vector dp(n + 1, vector<int>(2, 0));
        int ans = 0;
        for (int i = 1; i < n; i++) {
            bool odd = false, even = false;
            for (int j = i - 1; j >= 0 && (!odd || !even); j--) {
                if (!odd && (nums[i] + nums[j]) % 2 == 0) {
                    odd = true;
                    dp[i][0] = dp[j][0] + 1;
                }
                if (!even && (nums[i] + nums[j]) % 2 == 1) {
                    even = true;
                    dp[i][1] = dp[j][1] + 1;
                }
            }
            ans = max(ans, max(dp[i][0],dp[i][1]));
        }
        return ans + 1;
    }
};

int main(int argc, const char** argv) {
    Solution s;
    vector d = {1,1,7,3,2};
    debug(s.maximumLength(d));
    return 0;
}
